/*
	This file is part of the JKTest
    Copyright (C) 2008 Royce Y. Feng <ryfeng@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License version 3
    as published by the Free Software Foundation. You may not use, modify
    or distribute this program under any other version of the
    GNU Affero General Public License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package JKPanels;

import java.awt.Dimension;
import java.io.File;
import javax.swing.JOptionPane;

import jktest.JKMainPanel;
import jktest.JKMainGui;
import jktest.JMultilineLabel;
import jktest.JKButton;

/**
 * 
 * Panel Class containing all elements of the Partition Test
 * 
 * @author Royce Feng
 */
public class PartitionPanel extends JKMainPanel {

    private PassFailPanel passFail;
    
    /**
     * 
     * Main Constructor for PartitionPanel. Creates a multiline label with instructions
     * as well as the three main buttons: Start test, Pass, Fail.
     * 
     * @param _parent The Parent Class (for communication)
     */
    public PartitionPanel ( JKMainGui _parent ) {
        super(_parent);
        JMultilineLabel label = new JMultilineLabel();
        label.setMaxWidth(520);
        label.setText("After you click this button, JKTest will automatically determine the size of your hard " +
                "drive. Then it will determine whether or not the test passes.");
        this.add(label);
        JKButton button = new JKButton(this,"Partitions Check");
        button.setPreferredSize(new Dimension(200,25));
        this.add(button);
        passFail = new PassFailPanel(this);
        passFail.setPreferredSize(new Dimension(500,25));
        this.add(passFail);
    }
    
    /**
     * 
     * Returns the name of the panel
     * 
     * @return The name of the panel
     */
    @Override
    public String getName() {
        return "Partitions Check";
    }
    
    /**
     * 
     * Handles button clicks. Pass/fail gets sent to parent while the test is run
     * when the test button is clicked.
     * 
     * @param source Button source (usually the button text)
     */
    public void ButtonClicked( String source ) {
        if ( source.equals("Pass") ) {
            getThisParent().valChanged(this.getName(), true);
            getThisParent().incPanel();
        } else if ( source.equals("Fail") ) {
            getThisParent().valChanged(this.getName(), false);
            getThisParent().incPanel();
        } else {
            /*
            if ( getThisParent().getMessageState() )
                JOptionPane.showMessageDialog(this, "Partitions Check is an automated procedure. If you wish to check " +
                      "this manually, please open up a Disk Management Window and verify the size of the Partition.",
                        "Automated Procedure", JOptionPane.INFORMATION_MESSAGE);
            */
            File[] roots = File.listRoots();
            long hdSize = 0;
            for (int i=0; i < roots.length; i++) {
                File f = roots[i];
                hdSize += f.getTotalSpace();
            }
            double hdSizeGB = hdSize / 1024 / 1024 / 1024;
            getThisParent().valChanged(source,(hdSizeGB > 9));
        }
    }
    
}
